/*
 * 创建日期 2010-1-18
 *
 * 成都天和软件公司
 * 电话：028-85425861
 * 传真：028-85425861-8008
 * 邮编：610041 
 * 版权所有
 */
package  org.fantasy.common.util;

import java.util.Enumeration;

import javax.servlet.http.HttpServletRequest;

/**
 *  参数
 * @author: 王文成
 * @version: 1.0
 * @since 2010-1-18
 */
public class Parameter {
    
    public static int PARAM_TYPE_NORMAL = 1; 
    
    public static int PARAM_TYPE_QRY = 2;

    private HttpServletRequest request;
    
    private int type;
    
    public Parameter(HttpServletRequest request) {
        this(request,PARAM_TYPE_NORMAL);
    }

    public Parameter(HttpServletRequest request , int type ) {
        this.request = request;
        this.type = type;
    }
    
    public boolean isParameter(String name){
        return true;
    }

    public StringBuffer getElementHtml(String name) {
        StringBuffer html = new StringBuffer(256);
        String[] values = request.getParameterValues(name);
        if( PARAM_TYPE_QRY == type ){
            String ckbName = "ckb" + StringUtil.firstCharUpperCase(name);
            html.append("<input type='hidden' name='" + ckbName + "' value='true'/>\n");
        }
        for( String value : values ){
            html.append("<input type='hidden' name='" + name + "' value='" + value + "'/>\n");
        }
        return html;
    }

    @Override
    public String toString() {
        Enumeration enums = request.getParameterNames();
        StringBuffer html = new StringBuffer(256);
        while (enums.hasMoreElements()) {
            String name = (String) enums.nextElement();
            if( isParameter( name ))
                html.append(getElementHtml(name) + "\n");
        }
        return html.toString();
    }
}
